<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>单位信息维护</title>
<link rel="stylesheet" href="<%=path%>/css/bootstrap.min.css" />
<link rel="stylesheet" href="<%=path%>/css/easyui.css" />
<link rel="stylesheet" href="<%=path%>/css/icon.css" />
<script src="<%=path%>/js/jquery1.12.4.min.js"></script>
<style>
body {
	background-color: #f1f1f1;
}

.lightBg {
	background-color: #fff;
	padding: 5px 20px;
}

table { /* 	border:solid 1px black;
 */
	
}

td { /*  border:solid 1px black; 
 */
	height: 50px;
	width: 50px;
	text-align: left;
}
}
</style>
</head>
<body>

	<div class="container">
		<div class="row lightBg">
			<!--标题-->
			<h2 class="pull-left">
				<img src="<%=path%>/images/logo.png" style="width: 80px;">
				智游科技项目申报单位信息显示
			</h2>
		</div>
	</div>
	<div class="row" style="margin-top: 20px;" align="center">
		<div style=" margin:auto; background-color: #fff;padding: 20px;">
			<span style="color: gray">管理员信息</span>${permission}
			<hr>
			<!-- 可修改内容 -->
			<form id="companyInfo">
				<table title="管理员信息"
					style="margin-top:30px;height: 200px; width: 50%">
					<tr>
						<td style="text-align: right">管理员姓名:</td>
						<td><input id="td1" type="text" readonly="readonly"
							name="UName" value="${user.UName}" />
						</td>
					</tr>
					<%-- 				<tr>
					<td style="text-align: right">邮箱:</td>
					<td><input type="text" name="UPostcode" value="${user.UEamil}" />
						<input type="text" name="postcode" value="" /></td>
				</tr> --%>
					<tr>
						<td style="text-align: right">电话:</td>
						<td><input id="td2" type="text" readonly="readonly"
							name="UPhone" value="${user.UPhone}" /> <!-- <input id="code" type="text" readonly="readonly" name="phoneCode" value="" /> -->
						</td>
					</tr>
					<tr>
						<td style="text-align: right">证件类型:</td>
						<td><input id="td3" type="text" readonly="readonly"
							name="UPapertype" value="${user.UPapertype}" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right">证件号:</td>
						<td><input id="td4" type="text" readonly="readonly"
							name="UPapernum" value="${user.UPapernum}" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;">
							<!-- 					<span style="color: green" id="good"></span>
					<span style="color: red" id="bad"></span> --></td>
						<td>
							<span id="goodResult" style="color: green;" ></span>
							<span id="badResult" style="color: red;" ></span>
							<button id="b" style="color: black;">修改</button>
							<input type="text" id="code" name="code" placeholder="请输入验证码">
							<button id="c"  style="color: black;">提交验证码</button>
							 <!-- <input type="reset" > -->
						</td>
					</tr>
				</table>

			</form>
		</div>
</body>
</html>
<script>
	$(function() {
	
	
	
	write();
	//$("#code").attr("type","hidden");

		$("#c").click(function() {
		
		var code=$("#code").val();
			$.ajax({
				type : "POST",
				url : "checkCode?code="+code,
				async:false,
				success : function(data) {
				alert("现在可以修改了");
				}
			});
		
		});

		//绑定修改按钮
		$("#b").click(function() {
		//var re=new Array();
		//取得所有td标签的readonly值
/* 		re[0]=$("#td1").attr("readonly");
		re[1]=$("#td2").attr("readonly");
		re[2]=$("#td3").attr("readonly");
		re[3]=$("#td4").attr("readonly"); */
		//alert(readonly);
		//var check=0;
		//检查所有input的只读状态
/* 		for(i=0;i<re.length;i++){
  			// obj[i].id;
  			if(re[i]!="readonly"){
  			//如果存在不是只读的,check+1
  				check=check+1;
  			};
		} */
		//alert(check);
		//判断值.如果check == 0,说明全部为只读,则发送验证码
		if("${permission}"!=1){
		//alert("sendMs");
			//如果只读状态下,用户点击修改按钮,将发送验证码  //<%-- <%=path%>/sendMs --%>
				$.ajax({
				type : "POST",
				url : "sendMs",
				async:false,
				success : function(data){
				//alert();
					//$("#code").attr("type","text");
			write();
			location.reload(); 
			//$("#c").attr("type","text");
			
				},
			});   
			//alert(123);
			}
		if("${permission}"==1){
		//alert("update");
			$.ajax({
				type : "POST",
				url : "updateManager",
				data:$('#companyInfo').serialize(),
				url : "sendMs",
				success : function(data) {
				if(data=="更新失败"){
					$("#badResult").html(data);
				};
					$("#goodResult").html("更新成功!");
				}
			});
		};
		
		});
		

		
	});

	/* 	$(function() {

	 $("#b").click(function() {

	 alert();
	 $.ajax({
	 type : "POST",
	 url : "updateCompanyInfo",
	 data : $('#companyInfo').serialize(),// 你的formid
	 dataType : "text",
	 success : function(result) {
	 if(result=="true"){
	 alert("保存成功");//返回字符串没有生效
	 }
	 if(result=="false"){
	 alert("保存失败");
	 }
	 }
	 });
	 });
	 });
	 */
</script>

<script>

function write(){
			//如果session中找到permission的值为1,取消只读属性
		if("${permission}"==1){
			$("#td1").removeAttr("readonly");
			$("#td2").removeAttr("readonly");
			$("#td3").removeAttr("readonly");
			$("#td4").removeAttr("readonly");
			$("goodResult").html("您现在可以进行修改了");
			setTimeout(function(){
    		$("#goodResult").html("");
			},3000);
		};
}
		
</script>